<!DOCTYPE html>
<html>
 
<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width,initial-scale=1.0'>
    <meta http-equiv='X-UA-Compatible' content='ie=edge'>
    <title>Document</title>
    <style>
       *{

       }
    </style>
</head>
 
<body>
    <div id='app'>
        <!-- 2. 使用组件  赋值 -->
        <com-a :a="b"></com-a>
        <button @click="fn">增加1</button>
        <button @click="fn2">减小1</button>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script>
        Vue.component("com-a", {
            template: `
          <div>
             {{a}}
            </div>
        `,
            // 1. 定义一个属性(变量) 此时没值
            props: ["a"]
           
        });
        new Vue({
            el: '#app',
            data: {
                b:0
            },
            methods: {
                fn:function(){
                    this.b=this.b+1
                },
                fn2:function(){
                    if(this.b!=0){
                    this.b=this.b-1
                    }
                   
                }
            }
        });
    </script>
</body>
 
</html>